/**
 * @description sequelize 实例
 * @author malin
 */

const Sequelize = require('sequelize')

// 引入数据库配置
const { MYSQL_CONF } = require('../conf/db')
const { database, host, port, user, password } = MYSQL_CONF

// 引入环境变量
const { isProd, isTest } = require('../utils/env')

// 线上环境使用连接池
if(isProd) {
    conf.pool = {
        max: 5,
        min: 0,
        idle: 10000
    }
}

const conf = {
    host,
    dialect: 'mysql'
}

// 测试环境下，不打印sql语句
if(isTest) {
    conf.logging = () => {}
}

const seq = new Sequelize(database, user, password, conf)

module.exports = seq
